#include "crossbit/TBlock.h"

using namespace crossbit;

void TBlock::relocate( XTUint32 offset )
{
				// relocate to new buffer address
				tb_tcode += offset;

				std::vector<int>::iterator 	I = tb_relocations.begin(),
								E = tb_relocations.end();

				// for each relocation point, substract offset from it
				for (; I != E; ++I)
								// For relative jump instruction:
								//
								// new_EIP = old_EIP + disp32
								// => disp32 = new_EIP - old_EIP
								//		 = new_EIP - (old_EIP + offset)
								//		 = new_EIP - old_EIP - offset
								//		 = old_disp32 - offset
								*(XTUint32 *)(tb_tcode + *I) -= offset;		

}
